package com.jml.咕泡.手写mybatisV1.session;

import com.jml.咕泡.手写mybatisV1.config.GpConfiguration;
import com.jml.咕泡.手写mybatisV1.executor.Executor;
import com.jml.咕泡.手写mybatisV1.mapper.MapperProxy;
import java.lang.reflect.Proxy;

public class GpSqlSession {

	GpConfiguration configuration;
	private Executor executor;

	public GpConfiguration getConfiguration() {
		return configuration;
	}

	//关联起来
	public GpSqlSession(GpConfiguration configuration, Executor executor) {
		this.configuration = configuration;
		this.executor = executor;
	}

	public <T> T getMapper(Class<T> clazz) {
		return (T) Proxy.newProxyInstance(
				clazz.getClassLoader(),
				new Class[]{clazz},
				new MapperProxy(this,clazz));
	}

	//第一个参数是sql，第二个参数是sql中的参数
	public <T> T selectOne(String statement,Object parameter) throws Exception {
		return executor.execute(statement,parameter);
	}



}
